'use strict';

const { Service } = require('egg');
const SMSClient = require('@alicloud/sms-sdk');
// 短信
const accountSMS = {
    account: {
        accessKeyId: 'LTAIQczFRNhtxcwe',
        secretAccessKey: '5gjpWZykBqJ3ST21I0MyPg1YcjYAPc'
    },
    options: {
        SignName: '孙浩',
        TemplateCode: 'SMS_140260052'
    }
};

class SMS extends Service {
    async send({ phone, verfiyCode }) {
        // 初始化sms_client
        const smsClient = new SMSClient({ ...accountSMS.account });
        return smsClient.sendSMS({
            ...accountSMS.options,
            PhoneNumbers: phone,
            TemplateParam: `{"code":${verfiyCode}}`
        });
    }
}

module.exports = SMS;
